package com.dp.struts2.yc;

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;

import org.apache.struts2.util.ServletContextAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.dp.pojo.News;
import com.dp.pojo.PageCtrl;
import com.dp.pub.BasePageAction;
import com.dp.pub.SysProperty;
import com.dp.service.jdc.ChannelServiceImpl3;
import com.dp.service.jdc.IndexServiceImpl;
import com.dp.service.jdc.SearchServiceImpl;
import com.dp.vo.TChannels;

@Controller
@Scope("session")
public class SearchAction extends BasePageAction implements ServletContextAware{
	private List<TChannels> navChannels ;//一级导航
	private List<List<TChannels>> nav2Channels;
	private String serchText;
	private List<News> listnews;
	
	//分页数据
    private PageCtrl pageCtrl;
    private int pageSize = 10;
    private int pageNo = 0;
    private String channelid;
    @Override
    public void setServletContext(ServletContext arg0) {}
    @Autowired
    private ChannelServiceImpl3 channelService;
   
    @Autowired
    private SearchServiceImpl searchservice;
    @Autowired
    private IndexServiceImpl indexService;

    public String search2(){
        navChannels = indexService.getChannelsList(SysProperty.getPrep("hdnews_rootch"));
        nav2Channels = new ArrayList<List<TChannels>>();
        for (TChannels t : navChannels) {
            List<TChannels> temp = channelService.getLastChannels(t.getChannelId());
            nav2Channels.add(temp);
        }
        listnews = searchservice.searchNews(serchText,pageSize,pageNo);
        pageCtrl = searchservice.getSerachPageCtrl(serchText, pageNo, pageSize);
        return "searchlist";
    }
    
    public String search1(){

        return "search";
    }
    

	public String getChannelid() {
		return channelid;
	}

	public void setChannelid(String channelid) {
		this.channelid = channelid;
	}

	public PageCtrl getPageCtrl() {
		return pageCtrl;
	}

	public void setPageCtrl(PageCtrl pageCtrl) {
		this.pageCtrl = pageCtrl;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public List<News> getNews() {
		return listnews;
	}

	public void setNews(List<News> news) {
		this.listnews = news;
	}

	public String getSerchText() {
		
		return serchText;
	}

	public void setSerchText(String serchText) {
		this.serchText = serchText;
	}
	public List<TChannels> getNavChannels() {
		return navChannels;
	}

	public void setNavChannels(List<TChannels> navChannels) {
		this.navChannels = navChannels;
	}
	 public List<List<TChannels>> getNav2Channels() {
	        return nav2Channels;
	    }

    public void setNav2Channels(List<List<TChannels>> nav2Channels) {
        this.nav2Channels = nav2Channels;
    }
}
